package com.briup.oagg.dataset.generate;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.po.LikeTable;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * 运行逆向工程配置类，生成数据库对应的类和接口
 * @Author briup
 */
public class MybatisPlusGeneratorConfig {
    public static void main(String[] args) {
        /*数据库连接信息*/
        String url = "jdbc:mysql://IP:3306/oagg?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8";
        String username = "root";
        String password = "123456";

        /*项目所在磁盘目录*/
        String basePath = "D:\\oagg\\oagg-dataset\\";
        String filePath = basePath+"src\\main\\java";//设置包和代码指定输出目录
        String mapperXmlPath = basePath+"src\\main\\resources\\mappers\\basic";
        String parentPackage = "com.briup.oagg.dataset";//父包名
        String tablePrefix = "oagg_dss"; // 指定哪些前缀的表生成代码
        FastAutoGenerator.create(url,username,password)
                .globalConfig(builder -> {
                    builder.author("briup")
                            .disableOpenDir() //生成文件后不自动打开所在目录
                            .outputDir(filePath);
                }).packageConfig(builder -> {
                    builder.parent(parentPackage)
                            .controller("web.controller")
                            .entity("bean.basic")
                            .mapper("mapper.basic")
                            .pathInfo(Collections.singletonMap(OutputFile.xml,mapperXmlPath));
                })
                .strategyConfig(builder -> {
                    builder.likeTable(new LikeTable(tablePrefix)) //模糊表匹配 ，可以选择生成指定表对应的代码
                            .addTablePrefix(tablePrefix)
                            .controllerBuilder().enableFileOverride()
                            .enableRestStyle()
                            .serviceBuilder().enableFileOverride()
                            .mapperBuilder().enableBaseColumnList().enableBaseResultMap()
                            .enableFileOverride()
                            .entityBuilder().enableFileOverride()
                            .enableLombok().enableChainModel();
                }).templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
